import { SecondCareerItem } from "./SecondCareerItem";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ObjCreate } from "../../common/ObjCreate";
import { ResFileConst } from "../../../resource/ResFileConst";
import { MsgManager } from "../../../manager/MsgManager";
import { Language } from "../../../../../extend/language/Language";
import { CareerUtil } from "../../common/util/CareerUtil";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
type int = number;
//class SecondCareerSelect
    
    export  class SecondCareerSelect /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initView();
            this._btnOK.addEventListener(flash.events.MouseEvent.CLICK, this.clickOpenSecondCareerHandler);
            return;
        }

        public getCurSelectedCareer(): int
        {
            if (this._curItem == null) 
            {
                return 0;
            }
            return this._curItem.careerId;
        }

        public updateView(arg1: Array<any>): void
        {
            var loc2=null;
            var loc3=0;
            var loc1=0;
            while (loc1 < this._items.length) 
            {
                loc2 = this._items[loc1] as SecondCareerItem;
                if ((loc3 = int(arg1[loc1])) <= 0) 
                {
                    loc2.visible = false;
                }
                else 
                {
                    loc2.visible = true;
                }
                loc2.update(loc3);
                ++loc1;
            }
            return;
        }

        /* internal  */onClickItem(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=null;
            var loc1=0;
            while (loc1 < this._items.length) 
            {
                loc2 = this._items[loc1] as SecondCareerItem;
                loc2.selected = false;
                ++loc1;
            }
            this._curItem = arg1.currentTarget as SecondCareerItem;
            this._curItem.selected = true;
            Dispatcher.dispatchEvent(new DataEvent(EventName.SecondCareerItemSelected, this._curItem.careerId));
            return;
        }

        /* internal  */initView(): void
        {
            var loc2=null;
            ObjCreate.createBg(0, 0, 161, 455, this);
            this._btnOK = ObjCreate.createGLoadedButton(ResFileConst.SecondCareerOKBtn, 41, 413, 93, 38, this);
            this._items = [];
            var loc1=0;
            while (loc1 < 3) 
            {
                loc2 = new SecondCareerItem();
                loc2.x = 8;
                loc2.y = 30 + loc1 * 127;
                this.addChild(loc2);
                this._items.push(loc2);
                loc2.addEventListener(flash.events.MouseEvent.CLICK, this.onClickItem);
                ++loc1;
            }
            return;
        }

        /* internal  */clickOpenSecondCareerHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._curItem == null) 
            {
                MsgManager.showRollTipsMsg(Language.getString(80202));
                return;
            }
            var loc1=CareerUtil.getCareerName(this._curItem.careerId);
            Alert.show(Language.getStringByParam(80252, loc1), null, Alert.OK | Alert.CANCEL, null, this.AlertCloseHandler);
            return;
        }

        /* internal  */AlertCloseHandler(arg1: int): void
        {
            if (arg1 == Alert.OK) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.SecondCareerSelect, this._curItem.careerId));
            }
            return;
        }

        /* internal */ /* var */_items: Array<any>;

        /* internal */ /* var */_curItem: SecondCareerItem;

        /* internal */ /* var */_btnOK: GLoadedButton;
    }
